import time

import stats as stats
from openpyxl import load_workbook

# workbook = load_workbook(filename="测试.xlsx")    # 加载工作簿
# print(type(workbook))   # 打印类型
# print(workbook.sheetnames)  # 打印所有sheet名称
# sheet = workbook["工作业务"]    # 访问特定sheet名称
# cell = sheet['A1']
# cell.value = "业务需求"  # 更改A1单元格的值
# workbook.save("测试1.xlsx")    # 保存工作簿（工作簿名称不一致会自动另存为新Excel）

# sheet = workbook.active
# rows = (
#     (88, 46, 57),
#     (89, 38, 12),
#     (23, 59, 78)
# )
# for row in rows:
#     sheet.append(row)   # 末尾追加

# sheet["A1"] = 56
# sheet["A2"] = 43
# now = time.strftime("%x")
# sheet["A3"] = now
# sheet.cell(row=2, column=2).value = 2   # 定位坐标
# workbook.save("测试.xlsx")

# print(sheet)    # 打印特定sheet名称
# for row in sheet.rows:  # 方形覆盖数据区域,显示每个格子坐标
#     print(row)

book = load_workbook("测试.xlsx", data_only=True)  # 访问单元格的值
sheet = book.active   # 当前活动的sheet表，或者说默认打开时显示的表
rows = sheet.rows
values = []
for row in rows:
    for cell in row:
        values.append(cell.value)
print("Sum value: {0}".format(sum(values)))
print("Mean value: {0}".format(stats.mean(values)))
